using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;
using System.Data;
using DTO;

namespace DAO
{
    public static class MuonsachDAO
    {
        public static bool thempm(MuonsachDTO dto)
        {
            string sql = "insert into Phieumuon(MaDG,Ngaymuon,Ngayhentra,TinhTrang) values('" + dto.MaDG + "','" + dto.Ngaymuon + "','" + dto.Ngayhentra + "','" + dto.Tinhtrang + "')";
            return DataProvider.ExecuteNonQuery(sql);

        }
        public static int laymapm()
        {
            string sql = "select max(Mapm) from Phieumuon";
            OleDbCommand cmd = new OleDbCommand(sql, DataProvider.ketnoi());
            int maphieu = (int)cmd.ExecuteScalar();
            int maphieumoi = maphieu + 1;
            return maphieumoi;

        }
        public static bool themCTPM(MuonsachDTO dto)
        {
            string sql = "insert into CTPM(MaPM,MaSach,TenSach,Soluong) values("+dto.MaPM+"," + dto.MaSach + ",'" + dto.TenSach + "'," + dto.Soluong + ")";
            return DataProvider.ExecuteNonQuery(sql);
        }
        public static bool updatePM(MuonsachDTO dto)
        {
            string sql = "update Phieumuon set MaDG='"+dto.MaDG+"',Ngaymuon='"+dto.Ngaymuon+"',Ngayhentra='"+dto.Ngayhentra+"',Tinhtrang='"+dto.Tinhtrang+"' where Mapm="+dto.Mapm+"";
            return DataProvider.ExecuteNonQuery(sql);
        }
        public static bool updateCTPM(MuonsachDTO dto)
        {
            string sql = "update CTPM set MaSach='" + dto.MaSach + "',TenSach='" + dto.TenSach + "',Soluong=" + dto.Soluong + " where MaPM='"+dto.Tinhtrang+"";
            return DataProvider.ExecuteNonQuery(sql);
        }
    }
}
